import * as managerModel from '../../models/manager';
import { ValidException, EmptyException, SystemException } from '../../helps/exception';

export function* list({ page, number, order, direction }) {
  return yield managerModel.list(page, number, order, direction);
}

export function* add({ data = {} }) {
  const manager = yield managerModel.add(data);
  if (!manager) throw SystemException('操作失败');
  return { id: manager.id };
}

export function* get({ manager_id }) {
  if (!manager_id) throw ValidException('id 不能为空');
  const manager = yield managerModel.get(manager_id);
  if (!manager) throw EmptyException('无相关信息');
  return manager;
}

export function* put({ manager_id, data = {} }) {
  if (!manager_id) throw ValidException('id 不能为空');
  const b = yield managerModel.put(manager_id, data);
  if (!b) throw SystemException('操作失败');
  return { id: manager_id };
}

export function* del({ manager_id }) {
  if (!manager_id) throw ValidException('id 不能为空');
  const b = yield managerModel.del(manager_id);
  if (!b) throw SystemException('操作失败');
  return { id: manager_id };
}
